$(function(){
	var province2=allarea()
	console.log(province2)
    var page=1;
    var pagenum= 10;
    var fi =1;
	var tddata=[
		{
			key:'name',
			type:1,
			url:''
		},{
			key:'phone',
			type:1,
			url:'{:url("detail")}',
			id:137
		},{
			key:'birthday',
			type:1,
			url:''
		},{
			key:'age',
			type:1,
			url:''
		},{
			key:'sex2',
			type:1,
			url:''
		},{
			key:'occupation',
			type:1,
			url:''
		},
		{
			key:'source',
			type:1,
			url:''
		},
		{
			key:'id_number',
			type:1,
			url:''
		},{
			key:'company_name',
			type:1,
			url:''
		},
		{
			key:'department_name',
			type:1,
			url:''
		},
		{
			key:'live_number',
			type:1,
			url:''
		},
		{
			key:'province',
			type:1,
			url:''
		},
		{
			key:'is_check2',
			type:1,
			url:''
		},{
			key:'is_instead2',
			type:1,
			url:''
		},
		{
			key:'is_vip2',
			type:1,
			url:''
		}];
	
	var addoperation=``;
	var fields='';
	
	var data={
		page:1,
		pagenum:10
	}
	
	var where_json={}
	{if $Think.get.name}
		where_json.name=['like','%{$Think.get.name}%']
	{/if}
	{if $Think.get.phone}
		where_json.phone=['like','%{$Think.get.phone}%']
	{/if}
	{if $Think.get.company_name}
		where_json.company_name=['like','%{$Think.get.company_name}%']
	{/if}
	{if $Think.get.is_check}
		where_json.is_check=['in','{$Think.get.is_check}']
	{/if}
	
	data.where_json=JSON.stringify(where_json)
	ajaxpassenger(data)
	function ajaxpassenger(data){
		Load()
		$.ajax({
			type:'post',
			data:data,
			url:'{:url("adminapi/Passenger/passengerList")}',
			success:function(res){
				Load(1)
				console.log(res)
				if(res.code==1){
					for(var i=0;i<res.data.length;i++){
						if(res.data[i].sex==1){
							res.data[i].sex2='男'
						}else{
							res.data[i].sex2='女'
						}
						if(res.data[i].is_check==1){
							res.data[i].is_check2='是'
						}else{
							res.data[i].is_check2='否'
						}
						if(res.data[i].is_instead==1){
							res.data[i].is_instead2='是'
						}else{
							res.data[i].is_instead2='否'
						}
						if(res.data[i].is_vip==1){
							res.data[i].is_vip2='是'
						}else{
							res.data[i].is_vip2='否'
						}
	//判断省市县
//						if(res.data[i].province){
//							res.data[i].province2=province2[res.data[i].province].name
//							
//							if(res.data[i].city){
//								var ival = parseInt(res.data[i].city)
//								if(!isNaN(ival)){
//									console.log(res.data[i].city)
//									res.data[i].province2+=province2[res.data[i].province].city[res.data[i].city].name
//									if(res.data[i].district){
//										var ival2 = parseInt(res.data[i].district)
//										if(!isNaN(ival2)){
//											res.data[i].province2+=province2[res.data[i].province].city[res.data[i].city].district[res.data[i].district].name
//										}
//									}
//								}
//	//							
//								
//							}
//						}
						 
					}
//					$('tbody').html(tbodymainf2(res.data, 1, tddata, addoperation, 'driver_id'))
					console.log(res.data)
					  
					 //展示已知数据
					 	 table.render({
					    	elem: '#passenger'
						    ,cols: [[ //标题栏
						      {field: 'name', title: '姓名', width: 100, sort: true,fixed: 'left'}
						      ,{field: 'phone', title: '手机号', width: 150,fixed: 'left'}
						      ,{field: 'birthday', title: '出生年月', minWidth: 150}
						      ,{field: 'sex2', title: '性别', width: 80}
						      ,{field: 'occupation', title: '职业', minWidth: 150}
						      ,{field: 'source', title: '来源', minWidth: 150}
						      ,{field: 'id_number', title: '身份证', width: 150}
						      ,{field: 'company_name', title: '公司/单位', minWidth: 230}
						      ,{field: 'department_name', title: '部门', minWidth: 230}
						      ,{field: 'live_number', title: '居住证', width: 150}
						      ,{field: 'province2', title: '所在城市', minWidth: 150}
						      ,{field: 'is_check2', title: '审核员', minWidth: 80}
						      ,{field: 'is_instead2', title: '代打车', width: 80}
						      ,{field: 'is_vip2', title: 'vip', minWidth: 80}
						      
						    ]]
						    ,data:res.data
						    ,even: true
						    ,limit: data.pagenum
					
					  	});
					 //   分页
                     if (fi == 1) {
                        laypage.render({
                            elem: 'page',
                            count: res.count,
							layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
							theme: '#1E9FFF',
                            jump: function (obj, first) {
                                console.log(obj)
                                if (!first) {
                                    page = obj.curr;
                                    data.page = page;
                                    pagenum = obj.limit;
                                    data.pagenum = pagenum;
                                    ajaxpassenger(data);
                                } else {
            
                                }
                            }
						})
						$('.daochu').on('click',function(){
							var getkey="";
							for(var iii=0;iii<tddata.length;iii++){
								if(tddata[iii].key=='sex2'){
									for(var key in res.description){
										if(key=='sex'){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='sex' checked> ${tddata[iii].text}
											</label>
										</li>`
								}else if(tddata[iii].key=='province2'){
									for(var key in res.description){
										if(key=='province'){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='province' checked> ${tddata[iii].text}
											</label>
										</li>`
								}else if(tddata[iii].key=='is_check2'){
									for(var key in res.description){
										if(key=='is_check'){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='is_check' checked> ${tddata[iii].text}
											</label>
										</li>`
								}else if(tddata[iii].key=='is_instead2'){
									for(var key in res.description){
										if(key=='is_instead'){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='is_instead' checked> ${tddata[iii].text}
											</label>
										</li>`
								}else if(tddata[iii].key=='is_vip2'){
									for(var key in res.description){
										if(key=='is_vip'){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='is_vip' checked> ${tddata[iii].text}
											</label>
										</li>`
								}else{
									for(var key in res.description){
										if(key==tddata[iii].key){
											tddata[iii].text=res.description[key].name
										}
									}
									getkey+=`<li>
											<label class="am-checkbox">
											  <input type="checkbox" value="" data-key='${tddata[iii].key}' checked> ${tddata[iii].text}
											</label>
										</li>`
								}
								
							}
							layer.open({
								  type: 1,
								  title:false,
								  skin: 'layui-layer-rim', //加上边框
								  area: ['300px', '400px'], //宽高
								  content: `<div>
											 <div style='height:300px;overflow:auto;margin-bottom:30px'>
											  <ul class='daochuul' style="padding:10px;">${getkey}</ul>
											  </div>
											  <div style='text-align:center'>
											  <button class="layui-btn layui-btn-normal daochu_ok" type='button'>确定导出</button>
											  <button class='layui-btn layui-btn-danger am-radius' type='button'>取消导出</button>
											  </div>
										</div>`,
								success:function(){
									var ddata={}
									$('.daochu_ok').on('click',function(){
										ddata.fields="";
										var where_jsondao={};
										
										{if $Think.get.name}
											where_jsondao.name=['like','%{$Think.get.name}%']
										{/if}
										{if $Think.get.phone}
											where_jsondao.phone=['like','%{$Think.get.phone}%']
										{/if}
										{if $Think.get.company_name}
											where_jsondao.company_name=['like','%{$Think.get.company_name}%']
										{/if}
										{if $Think.get.is_check}
											where_jsondao.is_check=['in','{$Think.get.is_check}']
										{/if}
										ddata.where_json=JSON.stringify(where_jsondao)
										
										$('.daochuul li input[type="checkbox"]').each(function(){
											if(this.checked){
												ddata.fields+=($(this).data('key')+",")
											}
										})
										ddata.fields=ddata.fields.slice(0,ddata.fields.length-1)
										console.log(ddata.fields)
										
										window.open(`${api.passenger.down}?where_json=${ddata.where_json}&fields=${ddata.fields}`)
										
									})
									
								}
							});
						})
                        fi = 2;
                    }
				

				}else{
					Err(res.msg)
				}
			},
			error:function(){
				Err('请求失败')
			}
		})
	}
})
